package com.bbx.taxi.client.widget.Dailog;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import com.bbx.api.util.LogUtils;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.Util.IsActivityFinishUtils;
import com.bbx.taxi.client.widget.MaxByteLengthEditText;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.Spanned;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
/** 
 * @Path com.bbx.taxi.client.widget.Dailog.MySnTimeOutDialog.java
 * @Author 严旭文
 * @Date 2016-6-7 下午5:42:05
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 市内超时
 */
public class MySnTimeOutDialog extends Dialog implements
		android.view.View.OnClickListener {
	public interface onClickSnLeftListener {
		public void onClickSnLeft();
	}

	public interface onClickSnRightListener {
		public void onClickSnRight();
	}

	public onClickSnLeftListener monClickSnLeftListener;
	public onClickSnRightListener monClickSnRightListener;
	public LinearLayout layout_dailog;
	private LinearLayout layout_double;
	private TextView tv_title;
	private TextView tv_start;
	private TextView tv_end;
	private TextView tv_time;
	private Button btn_cencel, btn_confirm;
	private boolean cancelable = true;
	private Context context;
	private boolean isFinish = false;

	public MySnTimeOutDialog(Context context) {
		super(
				context,
				(MessageDialog.map_dialog.get(context.toString()) != null ? MessageDialog.map_dialog
						.get(context.toString()) : 0) == 0 ? R.style.Dialog_bocop
						: R.style.Dialog_bocop2);
		this.context = context;
		init();
	}

	private void init() {
		View contentView = View.inflate(context, R.layout.dailog_sntimeout, null);
		setContentView(contentView);
		tv_title = (TextView) findViewById(R.id.tv_title);
		btn_cencel = (Button) findViewById(R.id.btn_cencel);
		btn_confirm = (Button) findViewById(R.id.btn_confirm);
		layout_dailog = (LinearLayout) findViewById(R.id.layout_dailog);
		tv_start=(TextView)findViewById(R.id.tv_start);
		tv_end=(TextView)findViewById(R.id.tv_end);
		tv_time=(TextView)findViewById(R.id.tv_time);
		btn_cencel.setOnClickListener(this);
		btn_confirm.setOnClickListener(this);
		layout_dailog.setVisibility(View.GONE);
		this.setCancelable(false);
		contentView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (cancelable) {
					dismiss();
				}
			}
		});
	}

	@Override
	public void show() {
		super.show();
		Animation a = AnimationUtils.loadAnimation(context,
				R.anim.dialog_in);
		layout_dailog.startAnimation(a);
		layout_dailog.setVisibility(View.VISIBLE);
	}

	@SuppressLint("NewApi")
	@Override
	public void dismiss() {
		if(!IsActivityFinishUtils.isActivityFinish(context)){
		if(isFinish)
		super.dismiss();
		int size=MessageDialog.map_dialog.get(context.toString())!=null?MessageDialog.map_dialog.get(context.toString()):0;
		if(size>0){
			MessageDialog.map_dialog.put(context.toString(), size-1);
		}

		Animation a = AnimationUtils.loadAnimation(context, R.anim.dialog_out);
		layout_dailog.startAnimation(a);
		a.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation anim) {
			}

			@Override
			public void onAnimationRepeat(Animation anim) {
			}

			@Override
			public void onAnimationEnd(Animation anim) {
				isFinish = true;
				dismiss();
			}
		});
		}

	}
	@Override
	public void setCancelable(boolean flag) {
		cancelable = flag;
		super.setCancelable(flag);
	}
    public void setStart(String text){
    	if(text==null||text.equals("")){
    		tv_start.setVisibility(View.GONE);
		}
		else{
			tv_start.setVisibility(View.VISIBLE);
			tv_start.setText(text);
		}
    }
    public void setEnd(String text){
    	if(text==null||text.equals("")){
    		tv_end.setVisibility(View.GONE);
		}
		else{
			tv_end.setVisibility(View.VISIBLE);
			tv_end.setText(text);
		}
    }
    public void setTime(String text){
    	if(text==null||text.equals("")){
    		tv_time.setVisibility(View.GONE);
		}
		else{
			tv_time.setVisibility(View.VISIBLE);
			tv_time.setText(text);
		}
    }
	public void setTitle(String text) {
		if(text==null||text.equals("")){
			tv_title.setVisibility(View.GONE);
		}
		else{
			tv_title.setVisibility(View.VISIBLE);
			tv_title.setText(text);
		}
		
	}


	public void setLeftButtonText(String text) {
		btn_cencel.setText(text);
	}

	public void setRightButtonText(String text) {
		btn_confirm.setText(text);
	}

	public void setonClickSnLeftListener(onClickSnLeftListener honClickSnLeftListener) {
		monClickSnLeftListener = honClickSnLeftListener;
	}

	public void setonClickSnRightListener(
			onClickSnRightListener honClickSnRightListener) {
		monClickSnRightListener = honClickSnRightListener;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_cencel:
			if (monClickSnLeftListener != null)
				monClickSnLeftListener.onClickSnLeft();
			dismiss();
			break;
		case R.id.btn_confirm:
			if (monClickSnRightListener != null)
				monClickSnRightListener.onClickSnRight();
			dismiss();
			break;
		}

	}
}